﻿/*
 * @Description:广告管理页面js
 * @Author:hanjx
 * @Date:2015-07-28
 */
var AdList = {};
$(function () {
    var option = {
        titleID: "titleid",
        contentID: "contentdiv",
        currentClassName: "current",
        titleFun: getTitles,
        urlFun: getTabUrl,
        dataFun: getData,
        maodian: true,
        contentFun: null
    };
    //tab切换
    tabHelper(option);

    RefreshNumber();
    //批量克隆下拉框
    //$(".batch a").click(function () {
    //    $(this).next().toggle();
    //    other.showAndHide("#linkBatchClone", "popBatchClone");
    //    $(this).find("i").toggleClass("on");
    //});
    //多对一弹框
    $(".btn-more-to-one-clone").bind("click", function () {
        $.dialog({
            id: "MoreToOneClone",
            lock: true,
            title: "多对一克隆",
            content: $("#MoreToOneClone").html()
        });
    });
    //多对多弹框
    $(".btn-more-to-more-clone").bind("click", function () {
        $.dialog({
            id: "MoreToMoreClone",
            lock: true,
            title: "多对多克隆",
            ok: true,
            cancel: true,
            width: 400,
            content: $("#MoreToMoreClone").html()
        });
    });

    $("#seeRule").bind("click", function () {
        $.dialog({
            lock: true,
            title:"规则内容",
            content: "1、放盘个数≤45个；每放5个盘奖励一个'优房';</br></br>\
                      2、设置优房必须符合以下三个条件：</br></br>\
                        a、1张户型图、3张及以上室内图 </br></br>\
                        b、标题>=15字 </br></br>\
                        c、房源描述（广告描述4个框的字数之和）>=200字</br></br>\
                      3、'中原优房'将接受客户'假一罚百'举报，罚款将由经纪人承担，请谨慎发布;"
        });
    });
})

function getTitles() {    
    var titles = [];
    titles.push("出售房源<span id='CountSaleProperty'></span>");
    titles.push("出租房源<span id='CountRentProperty'></span>");
    titles.push("待上架区<span id='CountStayShelfArea'></span>");
    titles.push("克隆历史<span id='CountPropertyAdCloneHistory'></span>");
    return titles;
};

function getTabUrl(tabname) {
    if (tabname.indexOf("出售房源") > -1) {
        return "/advert/advert-sale-property";
    }
    if (tabname.indexOf("出租房源") > -1) {
        return "/advert/advert-rent-property";
    }
    if (tabname.indexOf("待上架区")>-1) {
        return "/advert/advert-stay-shelf-area";
    }
    if (tabname.indexOf("克隆历史")>-1) {
        return "/advert/advert-clone-history";
    }
    return "/advert/advert-sale-property";
};

function getData(tabname) {
    return [{ name: "key", value: tabname }];
};

AdList.Refresh = function (refresh) {
    var keyId = $(refresh).attr("keyid");
    var url = "/Advert/batch-refreshtime-propertyad";
    var reqData = {
        "keyId": keyId
    };
    $.AjaxAgency(url, reqData, function (data) {
        if (data == "ok") {
            $("#searchForm").submit();
        }
        else {
            $.OKDialogAgency('<div class="tc">' + data + '</div>');
        }
    });
};

/// <summary>
/// 获得中原外网上面的数字
/// </summary>
/// <returns></returns>
function RefreshNumber() {
    $.AjaxAgency('/advert/RefreshNumber', null, function (data) {
        if (data) {
            //$("#CountNewProperty").html(data["CountNewProperty"]);
            //$("#CountOldProperty").html(data["CountOldProperty"]);
            $("#CountPropertyAd").val(data["CountPropertyAd"]);
            //$("#CountIsPropertyAd").html(data["CountIsPropertyAd"]);
            var packCount = data["CountIsPropertyAd"] + "/ " + data["PackageCount"];
            $("#AdmPackageCount").html(packCount);
            var hotCount = data["CountIsHotPropertyAd"] + "/ " + data["CountHotPropertAd"];
            $("#AdmExcellentRoomCount").html(hotCount);
            $("#CountSaleProperty").html(data["CountSaleProperty"]);
            $("#CountRentProperty").html(data["CountRentProperty"]);
            $("#CountStayShelfArea").html(data["CountStayShelfArea"]);
            $("#CountPropertyAdCloneHistory").html(data["CountPropertyAdCloneHistory"]);
        }
    });
}

function setPageStartTime() {
    window.pageStartTime = new Date();
}
function setPageEndTime() {
    $("#timeCount").html("查询耗时" + timehelper.TimeDiffirence(window.pageStartTime, new Date()).msDiff + "毫秒");
}

var loadscript = {};

loadscript.beginSearch = function () {
    //此方法在分页控件中
    if ("undefined" != typeof ajaxpageronbegin) {
        ajaxpageronbegin();
    }
    setPageStartTime();
};
loadscript.pageOnSuccessFun = function () {
    setPageEndTime();
};